package com.snack.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snack.common.result.Result;
import com.snack.entity.pojo.Profit;
import com.snack.mapper.ProfitMapper;
import com.snack.service.ProfitService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * @author huangfuhao
 * @Date 2025/4/19
 */
@Service
public class ProfitServiceImpl extends ServiceImpl<ProfitMapper, Profit> implements ProfitService {

    @Override
    public Result getProfitReportsByDateRange(LocalDate startDate, LocalDate endDate, Long storeId) {
        QueryWrapper<Profit> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("date", startDate, endDate);

        if (storeId != null) {
            queryWrapper.eq("store_id", storeId);
        }

        List<Profit> profitReportsList = list(queryWrapper);
        return Result.success(profitReportsList);
    }
}
